﻿using AiMachineControl.IService;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AiMachineControl.Service
{
    public class AppsettingService: IAppsettingService
    {
        private readonly IConfiguration _configuration;
        public AppsettingService(IConfiguration configuration)
        {
            _configuration = configuration;
        }

        /// <summary>
        /// 根据节点名获取配置文件的值
        /// </summary>
        /// <param name="SectionName"></param>
        public string GetAppsetting(string SectionName)
        {
            var section = _configuration.GetSection(SectionName);
            return section.Value;
            //Console.WriteLine("当前配置文件的值为："+section.Value);
            //Console.ReadLine();
        }

        /// <summary>
        /// 封装要操作的字符
        /// </summary>
        /// <param name="sections">节点配置</param>
        /// <returns>String</returns>
        public string GetValue(params string[] sections)
        {
            try
            {
                if (sections.Any())
                {
                    return _configuration[string.Join(":", sections)];
                }
            }
            catch (Exception) { }

            return "";
        }
    }
}
